﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using PClass;

namespace LaserPrint
{
    public partial class MainForm : Form
    {
        private ModelForm modelForm=null;
        private Boolean isDViewShow = false;

        public MainForm()
        {
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer |
                    ControlStyles.ResizeRedraw |
                    ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
            this.UpdateStyles();
            InitializeComponent();
        }

        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                if (!DesignMode)
                {
                    if (MaximizeBox) { cp.Style |= (int)WindowStyle.WS_MAXIMIZEBOX; }
                    if (MinimizeBox) { cp.Style |= (int)WindowStyle.WS_MINIMIZEBOX; }
                    //cp.ExStyle |= (int)WindowStyle.WS_CLIPCHILDREN;  //防止因窗体控件太多出现闪烁
                    cp.ClassStyle |= (int)ClassStyle.CS_DropSHADOW;  //实现窗体边框阴影效果
                }
                return cp;
            }
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            videoPlayer1.Start();
            Thread.Sleep(1000);
            videoPlayer2.Start();
            Parameter.Electromotor electromotor = new Parameter.Electromotor();
            propertyGrid1.SelectedObject = electromotor;
        }

        private void btnScanFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog opfile = new OpenFileDialog();
            opfile.Title = "选择文件...";
            opfile.Filter = "(*.stl)|*.stl";//设置过滤器
            opfile.InitialDirectory = "C:\\";
            if (opfile.ShowDialog() != System.Windows.Forms.DialogResult.Cancel)
            {
                opfile.Title = opfile.FileName;//设置对话框的标题
                this.tbFilePath.Text = opfile.FileName;
            }
        }

        //[DllImport("GL.dll")]  //需添加using System.Runtime.InteropServices
        //public static extern void showWindow();
        [DllImport("GL.dll", EntryPoint = "ShowView", CharSet = CharSet.Unicode,
           CallingConvention = CallingConvention.StdCall)]
        public static extern void ShowView();
        private void btnOpen_Click(object sender, EventArgs e)
        {
            if (modelForm == null || modelForm.IsDisposed)
            {
                modelForm = new ModelForm();
            }
            modelForm.Show();
            this.DViews.Image = global::LaserPrint.Properties.Resources.modelclose;
            isDViewShow = !isDViewShow;
            ShowView();
        }

        private void DViews_Click(object sender, EventArgs e)
        {
            if (!isDViewShow)
            {
                if (modelForm == null||modelForm.IsDisposed)
                {
                    modelForm = new ModelForm();
                }
                modelForm.Show();
                this.DViews.Image = global::LaserPrint.Properties.Resources.modelclose;
            }
            else
            {
                modelForm.Close();
                this.DViews.Image = global::LaserPrint.Properties.Resources.modeledit;
            }
            isDViewShow = !isDViewShow;
        }

        private void expandablePanel5_Click(object sender, EventArgs e)
        {

        }

    }
    public enum WindowStyle : uint
    {
        WS_OVERLAPPED = 0x00000000,
        WS_POPUP = 0x80000000,
        WS_CHILD = 0x40000000,
        WS_MINIMIZE = 0x20000000,
        WS_VISIBLE = 0x10000000,
        WS_DISABLED = 0x08000000,
        WS_CLIPSIBLINGS = 0x04000000,
        WS_CLIPCHILDREN = 0x02000000,
        WS_MAXIMIZE = 0x01000000,
        WS_CAPTION = 0x00C00000,
        WS_BORDER = 0x00800000,
        WS_DLGFRAME = 0x00400000,
        WS_VSCROLL = 0x00200000,
        WS_HSCROLL = 0x00100000,
        WS_SYSMENU = 0x00080000,
        WS_THICKFRAME = 0x00040000,
        WS_GROUP = 0x00020000,
        WS_TABSTOP = 0x00010000,
        WS_MINIMIZEBOX = 0x00020000,
        WS_MAXIMIZEBOX = 0x00010000,
        WS_TILED = WS_OVERLAPPED,
        WS_ICONIC = WS_MINIMIZE,
        WS_SIZEBOX = WS_THICKFRAME,
        WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW,
        WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU |
                                WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX),
        WS_POPUPWINDOW = (WS_POPUP | WS_BORDER | WS_SYSMENU),
        WS_CHILDWINDOW = (WS_CHILD)
    }
    public enum ClassStyle
    {
        CS_DropSHADOW = 0x20000  //实现窗体阴影
    }
}
